package org.example.game.history;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/14 10:57
 */
public class Solution100352 {

    public static void main(String[] args) {
        System.out.println(new Solution100352().getSmallestString("45342"));
    }

    public String getSmallestString(String s) {
        StringBuilder sb = new StringBuilder();
        char cur = s.charAt(0);
        boolean flag = false;
        List<Character> odd = Arrays.asList('0','2','4','6','8');
        List<Character> even = Arrays.asList('1','3','5','7','9');
        for (int i = 0; i < s.length()-1; i++) {
            //判断奇偶性， 判断大小 是否交换
            char next = s.charAt(i+1);
            if(!flag && cur > next &&
                    ( (odd.contains(cur) && odd.contains(next) )
                            || (even.contains(cur) && even.contains(next)))){
                sb.append(next);
                flag = true;
            }else {
                sb.append(cur);
                cur = next;
            }
        }
        sb.append(cur);

        return sb.toString();
    }

}
